package fifth;

public class TestCircleWithPrivateData {
    public static void main(String[] args) {
        CirclePrivate c = new CirclePrivate(5.0);
        System.out.println("The area of the circle of radius "+ c.getRadius()+" is "+c.getArea());
        c.setRadius(c.getRadius()*1.1);
        System.out.println("The area of the circle of radius "+ c.getRadius()+" is "+c.getArea());
        System.out.println("The number of objects is  "+c.getNumberOfObjects());


    }
}

class CirclePrivate{
    private double radius =1;
    private static int numberOfObjects = 0;    // 只能在这个类中用
    public CirclePrivate(){
        numberOfObjects++;
    }
    public CirclePrivate(double newRadius){
        radius = newRadius;
        numberOfObjects++;
    }

    public double getRadius(){
        return radius;
    }
    public void setRadius(double newRadius){
        radius = (newRadius >=0)? newRadius :0;
    }
    public static int getNumberOfObjects(){
        return numberOfObjects;
    }
    public double getArea(){
        return radius*radius*Math.PI;
    }


}